package izzat.fit.dbservice.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import izzat.fit.dbservice.base.entity.BaseEntity;
import izzat.fit.dbservice.base.mapper.BaseMapper;
import izzat.fit.dbservice.entity.mine.Record;
import izzat.fit.dbservice.entity.mine.Schedule;
import izzat.fit.dbservice.entity.mine.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @InterfaceName: MineMapper
 * @Description:
 * @Author: Izzat
 * @Date: 2019-12-29 17:45
 * @Version
 */
@DS(value = "fit_mine_db")
@Mapper
public interface MineMapper extends BaseMapper{
    @Select("SELECT * FROM user")
    List<User> getAllUser();

    @Select("SELECT * FROM schedule WHERE userid = #{userId}")
    List<Schedule> getScheduleByUserId(int userId);

    @Select("SELECT * " +
            "FROM history " +
            "WHERE acc_id = #{acc_id} " +
            "AND data " +
            "BETWEEN #{start} AND #{end}")
    List<Record> findRecordByUserAndRange(@Param("acc_id") int user,
                                          @Param("start") int start,
                                          @Param("end") int end);

    @Insert("INSERT INTO history (acc_id, plan, data, duration) " +
            "VALUES (#{acc_id}, #{plan}, #{data}, #{duration})")
    int addRecord(Record record);

    @Update("UPDATE schedule SET plan = #{plan} WHERE date = #{date} " +
            "                           AND userid = #{userid}")
    int updatePlanByUserAndDate(@Param("plan")int plan,
                                @Param("userid")int userId,
                                @Param("date")int date);
}
